package com.auxiliary;

import java.util.ArrayList;
import java.util.List;

import com.myidis.response.PeakValleyRes;

public class PeakValleyCalculator {
	
	
	public static PeakValleyRes Calculate(List<Inflexion> infections1, List<Inflexion> infections2)
    {
        if (infections1 == null || infections2 == null)
        	return null;
        else if (infections1.size() == 0 || infections2.size() == 0)
        	return null;
        else if (infections1.size() - infections2.size() != 0)
        	return null;
        
        int num = infections1.size();
        List<Double> peakOrderList =new ArrayList<Double> ();
        List<Double> valleyOrderList =new ArrayList<Double> ();
        
        BasicCalculator basicCal = new BasicCalculator();
        for (int i = 0; i < num; i++)
        {
            if(infections1.get(i).isPeak()==true && infections2.get(i).isPeak()==true) 
            {
                peakOrderList.add((double)basicCal.getDatesDiff(infections1.get(i).getDate(), infections2.get(i).getDate()));
                //peakNum += 1;
            }
            if (infections1.get(i).isPeak() == false && infections2.get(i).isPeak() == false)
            {
               valleyOrderList.add((double)basicCal.getDatesDiff(infections1.get(i).getDate(), infections2.get(i).getDate()));
                //valleyNum += 1;
            }
        }
        if (peakOrderList.size() == 0  || valleyOrderList.size() ==0) return null;           
        
        return new PeakValleyRes(basicCal.calcAvg(peakOrderList), basicCal.calcAvg(valleyOrderList), basicCal.calcStdev(peakOrderList), basicCal.calcStdev(valleyOrderList));
    }
}
